#define  _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>



int int_cmp(const void* e1, const void* e2)
{
	return (*(int*)e1) - (*(int*)e2);
}

void Swap(char* e1, char* e2,size_t width)
{
	int i = 0;
	for (i = 0; i < width; i++)
	{
		char temp = *e1;
		*e1 = *e2;
		*e2 = temp;
		e2++;
		e1++;
	}
}
void bubble_sort(void* base, size_t num, size_t width, int (*cmp)(const void* e1, const void* e2))
{
	int i = 0;
	for (i = 0; i < num - 1; i++)
	{
		int j = 0;
		for (j = 0; j < num - i - 1; j++)
		{
			if (cmp((char*)base + j * width, (char*)base + (j + 1) * width) > 0)
			{
				Swap((char*)base + j * width, (char*)base + (j + 1) * width, width);
			}

		}
	}
}

void Print(int *arr,int sz)
{
	int i = 0;
	for (i = 0; i < sz; i++)
	{
		printf("%d ", *(arr + i));
	}
	printf("\n");
}
int main()
{
	int arr[] = { 5,3,6,2,9,8,7,4,1,0 };
	int sz = sizeof(arr) / sizeof(arr[0]);
	Print(arr, sz);
	bubble_sort(arr,sz,sizeof(arr[0]),int_cmp);
	Print(arr,sz);
	return 0;
}

